<template>
    <div class="card-statistics">
        <div id="chart" style="width: 1000px; height: 600px;"></div>
    </div>
</template>

<script>
import * as echarts from 'echarts'; // 引入 ECharts
import axios from "axios";

export default {
    data() {
        return {
            chartData: [],
            myChart: null
        }
    },
    async mounted() {
        try {
            const response = await axios.get("http://localhost:8080/chart/courseCostList");
            this.chartData = response.data.data
        }
        catch (error) {
            console.error(error);
        }
        this.myChart = echarts.init(document.getElementById("chart"));
        console.log(this.chartData);
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '销课统计',
                left: 'center'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'left'
            },
            series: [
                {
                    name: 'Access From',
                    type: 'pie',
                    radius: '50%',
                    data: this.chartData,
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        this.myChart.setOption(option);
    }
}
</script>

<style></style>